package com.base.caselib.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.base.caselib.R;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;


public class ChooseRoadShowAdapter extends RecyclerView.Adapter<ChooseRoadShowAdapter.MyHolder> {
    private final Context mContext;
    private List<Integer> list = new ArrayList<>();
    public ClickListener clickListener;


    public interface ClickListener {
        void onClickListener(int position);
    }

    public ChooseRoadShowAdapter(Context context) {
        this.mContext = context;
    }

    public void setClickListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_road_img, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        Glide.with(mContext).load(list.get(position)).into(holder.img);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickListener.onClickListener(list.get(position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setData() {
        list.add(R.drawable.ic_road_x);
        list.add(R.drawable.ic_road_t1);
        list.add(R.drawable.ic_road_t2);
        list.add(R.drawable.ic_road_t3);
        list.add(R.drawable.ic_road_t4);
        list.add(R.drawable.ic_road_y1);
        list.add(R.drawable.ic_road_y2);
        list.add(R.drawable.ic_road_y3);
        list.add(R.drawable.ic_road_y4);
        list.add(R.drawable.ic_bradge);
        list.add(R.drawable.ic_road_empty);
        notifyDataSetChanged();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        public ImageView img;

        public MyHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.img_road_show);
        }
    }
}
